<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 *
 * @ID hotelinfo.php
 * 住哪酒店分销联盟（酒店详情）模块
 * @date 2013-2-18
 * @author yuhailong zjj008@gmail.com
 * @copyright zhuna Inc , all rights reserved
 *
 */

class Hotelinfo extends CI_Controller 
{
    private $data;
    function __construct()
    {
        parent::__construct();
        $this->load->model('model_common');
        
        $this->load->model('model_layout');
        $this->load->library('tool');
        $this->load->model('model_hotel');
        $this->load->library('pagination');
                
        
        $this->data = array();
    }
    
	public function index()
	{
        //载入布局模型
        $layout = $this->model_layout->get_layout('hotelinfo');
        
        $hotelId = $this->uri->segment(2)!='' ? $this->uri->segment(2) : 7225; 
        //酒店详细信息
        $hotelInfo = $this->model_hotel->getHotelInfo($hotelId);
        //酒店所在城市id和城市名称
        $cityid = $hotelInfo['CityID'];
        $ecityid = $hotelInfo['ecityid'];
        $_GET['cityid'] =  $ecityid;
        $cityname = $hotelInfo['CityName'];
        $hotelName = $hotelInfo['HotelName'];
        $this->data['cityid'] = $ecityid;
        $this->data['cityname'] = $cityname;
        $this->data['hotelId'] = $hotelId;
        $this->data['hotelName'] = $hotelName;
        //处理酒店标签字段并赋值给$hotelInfo
        $hotelInfo['Tags'] = $this->tool->tags_ary($hotelInfo['Tags']) ;
        //酒店评论信息
        $this->getComment($hotelId,5);
        //酒店问答信息
        $this->getQuestion($hotelId,5);
        //处理酒店图片并赋值给$hotelInfo
        $hpicshow = $this->tool->hpicshow($hotelInfo['Hotelpictures']);
        $hotelInfo['hpicshow'] = $hpicshow;
        $hotelInfo['hpicshowNumber'] = count($hpicshow);
        //处理服务信息并赋值给$hotelInfo
        $Service = $this->tool->Select_Info($hotelInfo['Service']);
        $hotelInfo['Service'] = explode("、",rtrim($Service,'、')); 
        //处理地理位置并赋值给$hotelInfo
        $hotelInfo['Traffic'] =  $this->model_hotel->trafficShow($hotelInfo['Traffic']);
        //处理酒店星级
        $hotelInfo['star'] = $this->tool->hotelranknamenum($hotelInfo['star']);
        //处理好评
        $hotelInfo['HaoPing'] = $this->tool->hoteldianping($hotelInfo['HaoPing'],3);
        $hotelInfo['HaoPing'] = $hotelInfo['HaoPing'][0];
        //处理酒店附近地标
        $hotelInfo['NearbyPoints'] = $this->model_hotel->getLableByHotelXY($ecityid,$hotelInfo['lat'],$hotelInfo['lng']);
        //$this->dump($hotelInfo['NearbyPoints']);
        //初始化日期
        $tm1 = date("Y-m-d",mktime());   
        $tm2 = date("Y-m-d",(mktime()+345600)); 
        $this->data['sk_array'] =  array('tm1'=>$tm1,'tm2'=>$tm2);
        $this->data['order_api'] = ZHUNA_ORDER_API;
        //酒店模板
        $this->data['layout'] = $layout ;
        
        //更新浏览记录的cookie
        $this->model_common->setHistoryHotel($hotelId,$hotelName,$hotelInfo['Min_price']);
        
        //处理网页中的seo信息
        $keywords_array = $this->model_common->getKeywords('hotelinfo');
        $keywords_array = str_replace(array('{doname}','{hotelnames}','{cityname}'),array(CFG_WEBNAME,$hotelInfo['HotelName'],$hotelInfo['CityName']),$keywords_array);
        $this->data['keywords_array'] = $keywords_array;
        
        //侧边栏周边酒店用到的参数
        $roundhotel['sort'] = 'hotelinfo';
        $this->data['roundhotel'] = $roundhotel;
        
        $this->data['hotelInfo'] = $hotelInfo;
        $this->data['method'] = $this->uri->segment(1) ; 
        $this->load->view('hotelinfo',$this->data);
	}
	
    public function getComment($hotelId,$limit)
    {
        $getCommentList = $this->model_hotel->getCommentList($hotelId);
        $this->data['commentNumber'] = $getCommentList['retHeader']['totalput'];//评论数量 
        $this->data['commentList'] = array_slice($getCommentList['reqdata'],0,$limit);//评论列表
    }
    
    public function getQuestion($hotelId,$limit)
    {
        $getQuestionList = $this->model_hotel->getQuestionList($hotelId,$limit);
        $questionList = $getQuestionList['reqdata'];
        $this->data['questionNumber'] = $getQuestionList['retHeader']['totalput'];//问答数量
        $this->data['questionList'] = $questionList;
    }
}